package tech.aistar.controller;



import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import tech.aistar.dto.Result;
import tech.aistar.entity.*;
import tech.aistar.service.*;
import tech.aistar.service.impl.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@Controller

@RequestMapping("/user")
public class UserAction {
    @Autowired
    private UserServiceImpl userService;

    @Autowired
    public ISinchoiceService sinchoiceService;

    @Autowired
    public IManchoiceService manchoiceService;

    @Autowired
    public ICompletionService completionService;

    @Autowired
    public IProgrammingService programmingService;

    @RequestMapping("/info")
    public String userInfo() {
        return "person";
    }

    @RequestMapping("/person")
    public @ResponseBody
    Result personInfo(HttpServletRequest request, HttpSession session) {
        String uname = request.getParameter("uname");
        User user = userService.findUserBynickname(uname);
        session.setAttribute("level", userService.getUserLevel(user.getUsId()));
        session.setAttribute("user", user);
        session.setAttribute("tasks", userService.getUserTask(String.valueOf(user.getUsId())));
        session.setAttribute("mycollection", userService.fingByColId(Long.valueOf(user.getUsId())));
//        System.out.println(userService.fingByColId(Long.valueOf(user.getUsId())));
        session.setAttribute("wrongList", userService.getUserWrongtopics(Long.valueOf(user.getUsId())));
        session.setAttribute("score", userService.getUserExa(String.valueOf(user.getUsId())));
        return new Result("700", "123");
    }

    @RequestMapping("/update")
    public @ResponseBody
    Result updateUser(User user) {
        int count = userService.updateUser(user);
        if (count > 0) {
            return new Result("12", "更新成功");
        } else {
            return new Result("12", "更新失败");
        }
    }


}



